<?php
function list_all_cat($cid=0,$type=null){
    global $db,$buid;

            $sql="select * from ".PROMOCAT." where fid ='$cid' and uid=$buid order by id asc ";

            $db->query($sql);
            $re=$db->getRows();
            foreach($re as $v){
                $_SESSION['str'].="|__";
                if($type=="option")
		{
			if(!empty($_GET['id'])&&is_array($_GET['id'])&&in_array($v['id'],$_GET['id']))
				$str='selected';
			elseif(!empty($_GET['id'])&&$_GET['fid']==$v['id'])
				$str='selected';
			else
				$str=NULL;
			echo "<option value='".$v["id"]."' $str >".$_SESSION['str'].$v["name"]."</option>";
		}
                if(empty($type)){
                echo $_SESSION['str'].$v['name']."　　[<a href='?action=m&m=promo&s=admin_promo_cat&menu=info&id=$v[id]&fid=$v[fid]'>修改</a>　｜　<a onclick=\"return confirm('你确定吗？');\" href='?action=m&m=promo&s=admin_promo_cat&menu=info&did=$v[id]'>删除</a>]<br><br>";
                }
                if(!empty($v['id']))
		{
                $sql="select * from ".PROMOCAT." where fid ='$v[id]' and uid=$buid order by id asc ";
                $db->query($sql);
                if($db->num_rows()){
                    list_all_cat($v['id'],$type);
                }
                }
                $_SESSION['str']=substr($_SESSION['str'],0,strlen($_SESSION['str'])-3);
            }
        }
        unset($_SESSION['str']);
?>
